//
//  MusicViewCell.m
//  OpenEyes
//
//  Created by dllo on 15/9/11.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "MusicViewCell.h"

@implementation MusicViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier ];
    if (self) {
        
        
        
        self.picture = [[UIImageView alloc ]initWithFrame:CGRectMake(0, 0, W * 130, H * 130)];
        self.picture.layer.masksToBounds = YES;
        self.picture.layer.borderWidth = 1;
        self.picture.layer.cornerRadius = self.picture.frame.size.width / 2;
        self.picture.center=CGPointMake(WIDTH/2, HEIGHT/6);
        self.picture.layer.borderColor = [[UIColor whiteColor]CGColor];
        [self.contentView addSubview:self.picture];
        
        
        UIView *v =[[UIView alloc]initWithFrame:CGRectMake(0, 0, W *140, H*140)];
        v.layer.masksToBounds = YES;
        v.layer.borderWidth = 1;
        v.layer.cornerRadius = v.frame.size.width/2;
        v.center =CGPointMake(WIDTH/2, HEIGHT/6);
        v.layer.borderColor = [[UIColor colorWithRed:76./255 green:76./255  blue:76./255  alpha:0.2]CGColor];
        [self.contentView addSubview:v];
        
        UIView *v1 =[[UIView alloc]initWithFrame:CGRectMake(0, 0, W *150, H*150)];
        v1.layer.masksToBounds = YES;
        v1.layer.borderWidth = 1;
        v1.layer.cornerRadius = v1.frame.size.width/2;
        v1.center =CGPointMake(WIDTH/2, HEIGHT/6);
        v1.layer.borderColor = [[UIColor colorWithRed:76./255  green:76./255  blue:76./255 alpha:0.1]CGColor];
        [self.contentView addSubview:v1];
        
//        UIView *v2 =[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH/375 *160, HEIGHT/667*160)];
//        v2.layer.masksToBounds = YES;
//        v2.layer.borderWidth = 1;
//        v2.layer.cornerRadius = 80;
//        v2.center =CGPointMake(WIDTH/2, HEIGHT/6);
//        v2.layer.borderColor = [[UIColor colorWithRed:76./255 green:76./255 blue:76./255 alpha:0.1]CGColor];
//        [self.contentView addSubview:v2];

////

//

        UIImageView * image  = [[ UIImageView alloc]initWithImage:[UIImage imageNamed:@"erji.png"]];
        image.frame = CGRectMake(0, 0, 40, 40);
        image.center=CGPointMake(self.picture.frame.size.width/2, self.picture.frame.size.height/2);
        image.userInteractionEnabled = YES;
        [self.picture addSubview:image];
        
        
        self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.picture.frame.origin.y + HEIGHT/667*130+50, WIDTH, HEIGHT/667*40)];
        self.titleLabel.textAlignment = 1;

//        self.titleLabel.backgroundColor = [UIColor cyanColor];

        self.titleLabel.font = [UIFont systemFontOfSize:20];
        self.titleLabel.textColor = [UIColor colorWithRed:56./255 green:56./255 blue:56./255 alpha:1];

        [self.contentView addSubview: self.titleLabel];
        
        
        self.categoryLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.titleLabel.frame.origin.y +HEIGHT/667*40+20,WIDTH , HEIGHT/667*20)];
        self.categoryLabel.textAlignment = 1;

//        self.categoryLabel.backgroundColor = [UIColor magentaColor];

        self.categoryLabel.font = [UIFont systemFontOfSize:14];
        

        [self.contentView addSubview: self.categoryLabel];
        
        //
        self.blackView = [[UIView alloc]initWithFrame:CGRectMake(0, H * 340, WIDTH, 10)];
        self.blackView.backgroundColor = [UIColor colorWithWhite:0.220 alpha:1.000];
        [self addSubview:self.blackView];
        
        
        
    }
    return self;
}

-(void)add:(MusicModel *)mo
{

    NSString *name = @"gif.gif";
    NSString *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:name ofType:nil];
    NSData *imageData = [NSData dataWithContentsOfFile:filePath];
    UIImage *image = [UIImage sd_animatedGIFWithData:imageData];

    
    NSURL *url =[NSURL URLWithString:mo.coverImage];
    [self.picture sd_setImageWithURL:url placeholderImage:image];
    NSString * str =[NSString stringWithFormat:@"%@/%@",mo.producter,mo.category];
    self.titleLabel.text = mo.title;
    self.categoryLabel.text =str;
    
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
